﻿@{
    ViewBag.Title = "分店管理";
}
@section header
{
}
<table id="dg" title="分店管理" class="easyui-datagrid"
    url="/subhotel/get"
    toolbar="#toolbar" pagination="false"
    rownumbers="true" fitcolumns="true" singleselect="false" ctrlselect="true" striped="true">
    <thead>
        <tr>
            <th field="name" >分店名称</th>
            <th field="address">分店地址</th>
            <th field="phone">电话</th>
            <th field="fax">传真</th>
        </tr>
    </thead>
</table>

<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newAdd()">新增</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="edit()">编辑</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="destory()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width: 400px; height: 260px; padding: 10px 20px"
    closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" data-options="novalidate:true">
        <input name="subHotelId" type="hidden"/>
        <div class="fitem">
            <label>分店名称:</label>
            <input name="name" class="easyui-textbox" required="true" id="txtSubHotelName" />
        </div>
        <div class="fitem">
            <label>分店地址:</label>
            <input name="address" class="easyui-textbox" />
        </div>
        <div class="fitem">
            <label>电话:</label>
            <input name="phone" class="easyui-textbox" />
        </div>
        <div class="fitem">
            <label>传真:</label>
            <input name="fax" class="easyui-textbox" />
        </div>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="save()" style="width: 90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width: 90px">取消</a>
</div>
@section Scripts
{
<script type="text/javascript">
    var msgTitle = "分店管理";
    var actionUrl = "";
    function newAdd() {
        $('#dlg').dialog('open').dialog('setTitle', '新增分店');
        $('#fm').form('clear');
        actionUrl = "/subhotel/add";
        $('#txtSubHotelName').textbox('readonly', false);
    }
    function edit() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '编辑分店');
            //$('#txtSubHotelName').textbox('readonly', true);
            $('#fm').form('load', row);
            actionUrl = "/subhotel/update";
            $('#fm input[name=address]').prev().focus();//设置焦点
        }
    }
    function save() {
        if (!$('#fm').form('enableValidation').form('validate')) {
            return;
        }
        $.post(actionUrl,
                 $('#fm').serialize(),
                  function (data) {
                      var msg = '';
                      if (data.msg.length != 0) {
                          $.each(data.msg, function () {
                              msg = data.msg + msg + '<br/>';
                          });
                          $.messager.alert(msgTitle, msg, 'error');
                      }
                      else {
                          $.messager.alert(msgTitle, '提交成功！', 'info');
                          $('#dlg').dialog('close'); // close the dialog
                          $('#dg').datagrid('reload'); // reload data
                      }
                  });
    }
    function destory() {
        actionUrl = "/subhotel/remove";
        var rows = $('#dg').datagrid('getSelections');
        if (rows.length > 0) {
            $.messager.confirm('Confirm', '确实要删除吗?', function (r) {
                if (r) {
                    $.post(actionUrl,
                          JSON.stringify(rows),
                          function (data) {
                              var msg = '';
                              if (data.msg.length != 0) {
                                  $.each(data.msg, function (index, item) {
                                      msg = msg + item + '<br/>';
                                  });
                                  $.messager.alert(msgTitle, msg, 'error');
                              }
                              else {
                                  $.messager.alert(msgTitle, '提交成功！', 'info');
                                  $('#dlg').dialog('close'); // close the dialog
                                  $('#dg').datagrid('reload'); // reload data
                              }
                          });
                }
            });
        }
    }
</script>
}
